/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function onLoadAutocomplete(){
    $( "#telefono" ).autocomplete({
	source: function( request, response ) {
	    $.ajax({
		//url: "http://ws.geonames.org/searchJSON",
		url: "filtraTelefono.php",
		dataType: "jsonp",
		data: {
		    featureClass: "P",
		    style: "full",
		    maxRows: 6,
		    telefono: request.term
		},
		success: function( data ) {
		    response( $.map( data.telefonos, function( item ) {
			return {
			    label: item.fono ,
			    value: item.fono,
			    valor: item.id
			}
		    }));
		}
	    });
	},
	minLength: 2,
	select: function( event, ui ) {
	    //	    $("#idtelefono").val(ui.item.valor);
//	    log( ui.item ?
//		"Selected: " + ui.item.label :
//		"Nothing selected, input was " + this.value);
	    
	    if(ui.item){
		$("#idtelefono").val(ui.item.valor);
	    }else{
		$("#idtelefono").val("");
	    }
	    seleccionar= true;
	    $("#telefono").autocomplete("close");
//	    $("#cliente").autocomplete( "option" , "minLength" , 0 );
//	    $("#cliente").focus();
//	    $("#cliente").autocomplete("search");
	},
	change: function(event, ui) {
	    if(ui.item){
		$("#idtelefono").val(ui.item.valor);
	    }else{
		$("#idtelefono").val("");
	    }
	},
	open: function() {
	    $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
	},
	close: function() {
	    $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
	}
    });
    
}